package com.sd.view;

import java.util.Vector;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.alex.books.BaseBook;
import com.sd.activity.R;

public class BookAdapter extends BaseAdapter {

	private Vector<BaseBook> mBooks;
	private LayoutInflater mLayoutInflater;
	public BookAdapter(Context context,Vector<BaseBook> books){
		mBooks = books;
		mLayoutInflater = LayoutInflater.from(context);
	}
	
	public void addBooks(BaseBook book){
		mBooks.add(book);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mBooks.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mBooks.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		TextView bookInfo = null;
		if(convertView==null){
			convertView = mLayoutInflater.inflate(R.layout.bookview, null);
			bookInfo = (TextView)convertView.findViewById(R.id.book_info);
			convertView.setTag(bookInfo);
		}else{
			bookInfo = (TextView)convertView.getTag();
		}
		BaseBook book = mBooks.get(position);
		bookInfo.setText(book.mBookName);
		return convertView;
	}
	
	
}
